package com.qianfeng.wuyang.himalaya.adapter.clsssifyadapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.qianfeng.wuyang.himalaya.activity.Classify_ad_Activity;

import java.util.List;

/**
 * Created by ShenHao on 2016/12/5.
 */

public class Adapter_Classify_Footpager extends PagerAdapter implements View.OnClickListener {
    private List<ImageView> list;
    List<String >adhtmls;
    private Context context;
    private int i;
    public Adapter_Classify_Footpager(List<ImageView> list,List<String >adhtmls,Context context) {
        this.adhtmls=adhtmls;
        this.list = list;
        this.context=context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        view.setOnClickListener(this);
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        i=position;
        container.addView(list.get(position));
        return list.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView( list.get(position));
    }

    @Override
    public void onClick(View view) {
        Intent intent =new Intent(context, Classify_ad_Activity.class);
        if (i==2||i==0){
                intent.putExtra("url",adhtmls.get(1));
            }else if (i==3){
            intent.putExtra("url",adhtmls.get(2));
        }else if (i==4){
            intent.putExtra("url",adhtmls.get(3));
        }
        context.startActivity(intent);
    }
}
